package thread;

/**
 * Created with IntelliJ IDEA.
 * Description: 单例模式——例2懒汉模式
 * User: 王圆豪
 * Date: 2025-05-03
 * Time: 20:26
 */
class SingletonLazy{
    private volatile static SingletonLazy instance = null;
    private SingletonLazy(){}

    public static SingletonLazy getInstance(){
        if (instance == null) {
            synchronized (SingletonLazy.class) {
                if (instance == null) {
                    instance = new SingletonLazy();
                }
            }
        }
        return instance;
    }

}
public class Demo27 {
    public static void main(String[] args) {
        SingletonLazy s1 = SingletonLazy.getInstance();
        SingletonLazy s2 = SingletonLazy.getInstance();
        System.out.println(s1 == s2);
    }
}
